#!/usr/local/bin/ruby
$: << ".."
require "fann"
include Fann

puts "-> create new neural network."
nn = Ann.new([2, 4, 1], 1.0, 0.7)

puts "-> setup neural network parameter."
nn.training_algorithm = TRAIN_QUICKPROP
nn.activation_function_hidden =  SIGMOID_SYMMETRIC_STEPWISE
nn.activation_function_output =  SIGMOID_SYMMETRIC_STEPWISE
nn.activation_steepness_hidden = 1.0
nn.activation_steepness_output = 1.0

puts "-> training data load."
td = TrainData.load "xor.data"

puts "-> training neural network."
nn.train_on_data(td, 30000, 1000, 0.00001){|epoch, error|
  puts "#{epoch} #{error}"
}

puts "-> test neural network."
puts nn.test([0, 0], [-1])
puts nn.test([0, 1], [1])
puts nn.test([1, 0], [1])
puts nn.test([1, 1], [-1])
